﻿using ExcelAddIn.Common;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExcelAddIn
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            //加密密码
            string connectString= SqlHelper.GetConnString();
            string sqlStr = String.Format("select * from System.Account where LoginName='{0}' and Password='{1}'", textBoxAccount.Text, textBoxPassword.Text);
            var reader = SqlHelper.ExecuteReader(connectString, CommandType.Text, sqlStr);

            if (reader.HasRows)//写入注册表
            {
                RegistryHelper rh = new RegistryHelper();
                string registry = textBoxAccount.Text + textBoxPassword.Text + "LiuXiao322";
                rh.SetRegistryData(Registry.LocalMachine, "SOFTWARE\\TYExcelHelper\\Params\\Account", "SecurityKey", Md5Helper.GetMd5Hash(registry));
            }
        }
    }
}
